Skip to content

Conversation

@yutotakano
Copy link
Owner

This PR adds the source code C file for opus_compare, and calls into its main() function from Haskell as part of the test suite. This is intended to be a replacement for the test suite's dependency on the opus-tools package which provides the official opus_compare executable.

We employ some hacky workarounds to make this work, the most significant being that we use a wrapper C file around opus_compare.c, which includes the original source, but removes fprintfs to keep the test suite output clean and rewrites main to be a different symbol to prevent clashes with Haskell's main. These workarounds enable us to keep opus_compare.c identical to upstream, simplifying any updates or modifications.

The test suite has been rewritten to use this Haskell-C-FFI version of opus_compare.

The CI now also downloads a copy of the Opus test vectors, which are necessary to run the test suite.

The goal is to have opus_compare in source code format (for minimal
footprint), and ideally in unaltered form from the Xiph repo for easy
updates/reproducibility.

We (ab)use the fact that Cabal can compile normal C code. Specifically,
we build opus_compare.c and link to it from Haskell and call into its
main function using an FFI wrapper (OpusCompare.hs). To avoid having
multiple definitions of main(), we use the cc-options field in the
cabal file to rename the main function in opus_compare.c to
opus_compare_main.

This is a bit of a hack, but it works and is simple. No more need to run
gcc separately and have a separate executable, or to need to install
opus-tools locally!
@yutotakano yutotakano merged commit 79c759c into master Feb 14, 2025
4 checks passed
@yutotakano yutotakano deleted the yutotakano/include-opus-compare-in-repo branch February 14, 2025 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants